package com.example.controller;

import com.example.common.Result;
import com.example.entity.Version;
import com.example.service.VersionService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 固件版本Controller
 */
@RestController
@RequestMapping("/api/version")
public class VersionController {
    
    @Resource
    private VersionService versionService;
    
    /**
     * 分页查询固件版本
     */
    @GetMapping("/page")
    public Result<PageInfo<Version>> page(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) Integer phoneId,
            @RequestParam(required = false) String region,
            @RequestParam(required = false) String version) {
        PageInfo<Version> pageInfo = versionService.page(pageNum, pageSize, phoneId, region, version);
        return Result.success(pageInfo);
    }
    
    /**
     * 根据ID查询固件版本
     */
    @GetMapping("/{id}")
    public Result<Version> getById(@PathVariable Integer id) {
        Version version = versionService.getById(id);
        return Result.success(version);
    }
    
    /**
     * 新增固件版本
     */
    @PostMapping
    public Result<?> add(@RequestBody Version version) {
        versionService.add(version);
        return Result.success();
    }
    
    /**
     * 更新固件版本
     */
    @PutMapping
    public Result<?> update(@RequestBody Version version) {
        versionService.update(version);
        return Result.success();
    }
    
    /**
     * 删除固件版本
     */
    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable Integer id) {
        versionService.delete(id);
        return Result.success();
    }
} 